<?php
include 'secure/core.php';
include 'user_header.php';
include 'left.php'; 
?>
<?php 
if(isset($_POST['submit'])){
$uploaddir = $settings->getUploadPath();
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$name = $_FILES['userfile']['name'];
$size = $_FILES['userfile']['size'];
$uploaded_by = $_SESSION['userid'];
$rand =  substr(md5(rand(1,100)),1,8);
$now = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$string = RAND();

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  $query = "INSERT INTO `uploads` SET `file_title` = '$name', `file_size` = '$size', `file_path` = '$uploaddir', `uploaded_by` = '$uploaded_by', `created_date` = '$now', `status` = '1', `ip_address` = '$ip', `string` = '$rand'";
  $result = mysql_query($query);
  echo '<script type="text/javascript">
        window.location = "upload.php?msg=1"
        </script>';

} else {
   echo '<script type="text/javascript">
        window.location = "upload.php?msg=2"
        </script>';

}
}
?>

		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
		<div class="message green"><span><b>Success</b>: Your file has been successfully uploaded.</span></div>
		<?php } ?>
		<?php if($_GET['msg'] == '2') { ?>
		<div class="message red"><span><b>Error</b>: There was an error uploading your file.</span></div>
		<?php } ?>
				<div class="box">
					<div class="title">
						File Upload
						<span class="hide"></span>
					</div>
					<div class="content">
						<form enctype="multipart/form-data" action="upload.php" method="POST">
                                                        <div class="row">
								<label>Browse</label>
								<div class="right"><input type="file" style="position: relative; height: 28px; width: 150px; display: inline; cursor: pointer; opacity: 0; margin-left: -65px; " name="userfile"></div>
							</div>
							<div class="row">
								<label>Upload</label>
								<div class="right">
								<button type="submit" class="green" name="submit"><span>Sumbit</span></button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
<?php include 'footer.php'; ?>